package com.karaoke.android.home.widget

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.TextView
import com.karaoke.android.home.R
import com.labo.kaji.relativepopupwindow.RelativePopupWindow

/**
 * Created by Allen on 16/8/19.
 */
class AuraButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(
        context,
        attrs,
        defStyleAttr)
{


    private val titleView: TextView
    val iconBtn: ImageButton

    private val popupWindow by lazy { AuraPopup(context) }

    init
    {
        View.inflate(context, R.layout.popupbutton, this)
        titleView = findViewById(R.id.title) as TextView
        iconBtn = findViewById(R.id.icon) as ImageButton
        titleView.text = "气氛"
        iconBtn.setImageResource(R.mipmap.ic_qifen)
    }

    override fun onTouchEvent(me: MotionEvent): Boolean
    {
        if (me.action == MotionEvent.ACTION_DOWN)
        {
            popupWindow.showOnAnchor(iconBtn, RelativePopupWindow.VerticalPosition.ALIGN_BOTTOM, RelativePopupWindow.HorizontalPosition.CENTER,0,20)

        }
//        if (me.action == MotionEvent.ACTION_UP)
//        {
//            if (popupWindow.isShowing)
//            {
//                popupWindow.dismiss()
//            }
//            onClickListener?.onClick(this)
//        }
        return super.onTouchEvent(me)
    }
}